package com.example.campus.controller.admin;

import com.example.campus.pojo.dto.UserPageQueryDTO;
import com.example.campus.pojo.dto.UserStatusChangeDTO;
import com.example.campus.result.PageResult;
import com.example.campus.result.Result;
import com.example.campus.service.UserService;
import com.example.campus.utils.constant.MessageConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminUserController")
@RequestMapping("/admin/user")
@Slf4j
@Api(tags = "管理端用户相关接口")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    @ApiOperation("用户分页查询（得到所有用户信息）")
    public Result<PageResult> userList(UserPageQueryDTO userPageQueryDTO) {
        PageResult pageResult = userService.getUserList(userPageQueryDTO);
        return Result.success(pageResult, MessageConstant.GET_LIST_SUCCESS);
    }

    @PutMapping("/statusChange")
    @ApiOperation("修改用户状态")
    public Result changeUserStatus(@RequestBody UserStatusChangeDTO userStatusChangeDTO) {
        userService.changeUserStatus(userStatusChangeDTO);
        return Result.success(MessageConstant.CHANGE_USER_STATUS_SUCCESS);
    }
}
